package cn.smy.dama2;
import Decoder.BASE64Decoder;
import cn.smy.dama2.*;
import cn.smy.dama2.Dama2Web.DecodeResult;
import cn.smy.dama2.Dama2Web.ReadBalanceResult;
import cn.smy.dama2.Dama2Web.ReadInfoResult;
import cn.smy.dama2.Dama2Web.RequestResult;

import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1325980466616825482L;
	private Dama2Web dama2 = new Dama2Web(45642, "e0f23515354ae338d1ece9979f2eecf9", "nickboowen100", "nickboowen");
	private int id;

	public MainFrame() throws HeadlessException {
		this.setLayout(new FlowLayout());
		
		//query balance
		JButton getBalanceButton = new JButton("queryBalance");
		getBalanceButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ReadBalanceResult res = dama2.getBalance();
				String s;
				if (res.ret >= 0) {
					s = "balance=" + res.balance;
				} else {
					s = "failed: ret = " + res.ret + "; desc=" + res.desc;
				}
				JOptionPane.showMessageDialog(null, s);
			}
			
		});
		getContentPane().add(getBalanceButton);
		
		//read info
		JButton readInfoButton = new JButton("readInfo");
		readInfoButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ReadInfoResult res = dama2.readInfo();
				String s;
				if (res.ret == 0) {
					s = "name=" + res.name + "; qq=" + res.qq + "; email="  + res.email + "; tel=" + res.tel;
				} else {
					s = "failed: ret = " + res.ret + "; desc=" + res.desc ;
				}
				JOptionPane.showMessageDialog(null, s);
			}
			
		});
		getContentPane().add(readInfoButton);
		
		//通过URL请求打码
		JButton decodeUrlButton = new JButton("decodeUrl");
		decodeUrlButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				int type = 42;
				int timeout = 30;
				String url = "http://icode.renren.com/getcode.do?t=web_reg&rnd=1383107243557";
				DecodeResult res = dama2.decodeUrlAndGetResult(url, type, timeout);
				String s;
				if (res.ret >= 0) {
					id = res.ret;
					s = "success: result=" + res.result + "; id=" + res.ret + "; cookie=" + res.cookie;
				} else {
					s = "failed: ret = " + res.ret + "; desc=" + res.desc ;
				}
				JOptionPane.showMessageDialog(null, s);
			}
			
		});
		getContentPane().add(decodeUrlButton);

		//通过URL请求打码
		JButton decodeButton = new JButton("decode");
		decodeButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				int type = 200;
				int timeout = 30;
				JFileChooser fc = new JFileChooser();
				fc.showOpenDialog(null);
				File file = fc.getSelectedFile();
				if (file == null)
					return;
				
				FileInputStream fis;
				byte [] data = new byte[(int)file.length()];
				try {
					fis = new FileInputStream(file);
					fis.read(data);
					fis.close();
				} catch (FileNotFoundException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "open file failed");
					return;
				} catch (IOException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "read file failed");
					return;
				}
				BASE64Decoder decoder = new BASE64Decoder();  
				//data:image/jpeg;base64, /9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABGAKADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZW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BsoX2yZeXA+bgL9OmdvGfWpXS2E96GWUpGmSN5yx75Oee3XPeiigBESEtYqfM3yffIY/p6fNjpjimMIPs106rJ8sgWMFuM9iR35z1zRRQBMI7b7ckYE23ydzHzDk8cc5z0zx0qAeQbKF9smXlwPm4C/Tpnbxn1oooAldLYT3oZZSkaZI3nLHvk557dc96REhLWKnzN8n3yGP6enzY6Y4oooAYwg+zXTqsnyyBYwW4z2JHfnPXNTCO2+3JGBNt8ncx8w5PHHOc9M8dKKKAIB5BsoX2yZeXA+bgL9OmdvGfWpXS2E96GWUpGmSN5yx75Oee3XPeiigD/9k=";
				try {
					data = decoder.decodeBuffer(imgStr);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				DecodeResult res = dama2.decodeAndGetResult(type, timeout, data);
				String s;
				if (res.ret >= 0) {
					id = res.ret;
					s = "success: result=" + res.result + "; id=" + res.ret;
				} else {
					s = "failed: ret = " + res.ret + "; desc=" + res.desc ;
				}
				JOptionPane.showMessageDialog(null, s);
			}
			
		});
		getContentPane().add(decodeButton);

		//文本题
		JButton decodeTextButton = new JButton("decodeText");
		decodeTextButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				int type = 106;
				int timeout = 30;
								
				DecodeResult res = dama2.decodeAndGetResult(type, timeout, "一加上五");
				String s;
				if (res.ret >= 0) {
					id = res.ret;
					s = "success: result=" + res.result + "; id=" + res.ret;
				} else {
					s = "failed: ret = " + res.ret + "; desc=" + res.desc ;
				}
				JOptionPane.showMessageDialog(null, s);
			}
			
		});
		getContentPane().add(decodeTextButton);
		
		//read info
		JButton reportErrorButton = new JButton("reportError");
		reportErrorButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				RequestResult res = dama2.reportError(id);
				String s;
				if (res.ret == 0) {
					s = "report success(id=" + id + ")";
				} else {
					s = "failed: ret = " + res.ret + "; desc=" + res.desc ;
				}
				JOptionPane.showMessageDialog(null, s);
			}
			
		});
		getContentPane().add(reportErrorButton);

		this.pack();
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}


}
